package designpattern.singleton;

import java.io.Serializable;

/**
 * @author or2
 * @Description 使用静态内部类 利用 JVM的机制 实现安全的单例模式
 * @create 2021年09月01日 时间: 15:45
 */
public class StaticInnerClass implements Serializable {
    private StaticInnerClass(){}

    private static class InnerClass{
        private static final StaticInnerClass staticInnerClassSingleton = new StaticInnerClass();
    }

    public static StaticInnerClass getInstance() {
        return InnerClass.staticInnerClassSingleton;
    }

//    @java.io.Serial
    private Object readResolve() {
        return InnerClass.staticInnerClassSingleton;
    }
}
